package com.ken.common.security.config;

import com.ken.common.security.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    // 配置拦截规则：
    //    排除登录接口和测试接口，避免拦截器对这些路径进行不必要的处理。
    //    拦截其他所有路径，确保请求经过身份验证。
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .excludePathPatterns("/**/login", "/**/test/**").addPathPatterns("/**");
    }
}
